home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / digtlclk / loadme.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  10.1 KB  |  270 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. --*******************************************************************************
  3. --*          Demo for:    DigitalClock
  4. --*    Required files: digtlclk.sx
  5. --*            Author:    Su Quek - Kaleida Labs, Inc.
  6. --*-----------------------------------------------------------------------------*
  7. --*       Description: This script demonstrates how to create a digital clock/
  8. --*                    stopwatch.
  9. --*                    When you run "digtlclk.sxt", you should see a window
  10. --*                    with digital time display.  Press the clock/stopwatch button 
  11. --*                    to switch between the clock display and the stopwatch.
  12. --*                    Press the start/stop button and the reset button to start 
  13. --*                    or stop and reset the stopwatch. 
  14. --*******************************************************************************
  15.  
  16. module DigitalClockModule
  17.     uses ScriptX
  18. end
  19.  
  20. in module DigitalClockModule
  21.  
  22. --*=============================================================================*
  23. --* Set up DirReps
  24. --*=============================================================================*
  25. global mediaDir := spawn theScriptDir "media"
  26.  
  27.  
  28. --*=============================================================================*
  29. --* Load required files
  30. --*=============================================================================*
  31. -- Load Digital Clock
  32. fileIn theScriptDir name:"digtlclk.sx"
  33.  
  34.  
  35. --*=============================================================================*
  36. --*    Define Demo 
  37. --*=============================================================================*
  38. class Demo (Window)
  39. inst vars
  40.     digitalClock
  41. end
  42.  
  43. --*=============================================================================*
  44. --*       Method name:    importBitmap
  45. --*             Class:    Demo
  46. --*             Usage: importBitmap self mediaDir bitmapFile
  47. --*                        mediaDir    - DirRep
  48. --*                        bitmapFile  - String object
  49. --*-----------------------------------------------------------------------------*
  50. --*       Description: Imports the given bitmap from the given directory.
  51. --*=============================================================================*
  52. method importBitmap self {class Demo} mediaDir bitmapFile ->
  53. (
  54.     local theStream := getStream mediaDir bitmapFile @readable
  55.     local theColormap := importMedia theImportExportEngine theStream @image @dib @colormap
  56.     local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap \
  57.                     colormap:theColormap --container:self.title
  58.     return theBMP
  59. )
  60.  
  61. --*=============================================================================*
  62. --*       Method name:    makeButtons
  63. --*             Class:    Demo
  64. --*             Usage: makeButtons self 
  65. --*-----------------------------------------------------------------------------*
  66. --*       Description: Creates and lays out the start/stop button, the reset button
  67. --*                    and the clock/stopwatch button in the demo window.
  68. --*=============================================================================*
  69. method makeButtons self {class Demo} ->
  70. (
  71.     --*=========================================================================*
  72.     --* Create an actuator controller to control all the buttons in the demo
  73.     --*    window.
  74.     --*=========================================================================*
  75.     new ActuatorController space:self wholespace:true
  76.  
  77.     --*=========================================================================*
  78.     --* Import all required bitmaps
  79.     --*=========================================================================*
  80.     local mediaDir := spawn theScriptDir "media"
  81.     local clockBitmap := (importBitmap self mediaDir "clock.bmp")
  82.     local stopwatchBitmap := (importBitmap self mediaDir "stopwtch.bmp")
  83.     local resetRelBitmap := (importBitmap self mediaDir "resetrel.bmp")
  84.     local resetPrsBitmap := (importBitmap self mediaDir "resetprs.bmp")
  85.     local resetDisBitmap := (importBitmap self mediaDir "resetdis.bmp")
  86.     local startBitmap := (importBitmap self mediaDir "start.bmp")
  87.     local stopBitmap := (importBitmap self mediaDir "stop.bmp")
  88.     local disabledBitmap := (importBitmap self mediaDir "startdis.bmp")
  89.     
  90.     --*=========================================================================*
  91.     --* Create the start/stop button
  92.     --*=========================================================================*
  93.     object startToggle (Toggle)
  94.         toggledOnPresenter    : (new TwoDShape boundary:stopBitmap) 
  95.         toggledOffPresenter    : (new TwoDShape boundary:startBitmap) 
  96.  
  97.         -- **** BUG!!! ****
  98.         -- Setting the disabled presenter of a toggle to a bitmap returns:
  99.         -- ** Not yet implemented #<Generic Substrate:widthSetter>. (Unimplemented)
  100.         -- disabledPresenter    : (new TwoDShape boundary:disabledBitmap) 
  101.         settings
  102.             x                : 140
  103.             y                : 60
  104.             enabled            : false
  105.             authordata         : self.digitalClock
  106.             activateAction    : (authordata self toggledOn -> (
  107.                                     if toggledOn then
  108.                                         start authordata
  109.                                     else
  110.                                         stop authordata
  111.                               ))
  112.     end
  113.     
  114.     --*=========================================================================*
  115.     --* Create the reset button
  116.     --*=========================================================================*
  117.     object resetButton (PushButton)
  118.         releasedPresenter    : (new TwoDShape boundary:resetRelBitmap)
  119.         pressedPresenter    : (new TwoDShape boundary:resetPrsBitmap)
  120.         disabledPresenter    : (new TwoDShape boundary:resetDisBitmap)
  121.         settings
  122.             x                : 140
  123.             y                : 85
  124.             enabled            : false
  125.             authordata        : self.digitalClock
  126.             activateAction  : (authordata self -> (
  127.                                     reset authordata
  128.                                     toggleOff startToggle
  129.                               ))
  130.     end
  131.     
  132.     --*=========================================================================*
  133.     --* Create the clock/stopwatch button
  134.     --*=========================================================================*
  135.     object clockToggle (Toggle)
  136.         toggledOnPresenter    : (new TwoDShape boundary:clockBitmap)
  137.         toggledOffPresenter    : (new TwoDShape boundary:stopwatchBitmap)
  138.         settings
  139.             x                : 10
  140.             y                : 73
  141.             authordata        : self.digitalClock
  142.             activateAction  : (authordata self toggledOn -> (
  143.                                     if toggledOn then
  144.                                     (
  145.                                         authordata.mode := @stopwatch
  146.                                         startToggle.enabled := true
  147.                                         resetButton.enabled := true
  148.                                     )
  149.                                     else
  150.                                     (
  151.                                         authordata.format := @12hour
  152.                                         authordata.mode := @clock
  153.                                         toggleOff startToggle
  154.                                         startToggle.enabled := false
  155.                                         resetButton.enabled := false
  156.                                     )
  157.                               ))
  158.     end
  159.  
  160.             
  161.     --*=========================================================================*
  162.     --* Append all buttons to the demo window
  163.     --*=========================================================================*
  164.     append self startToggle
  165.     append self resetButton
  166.     append self clockToggle
  167.                              
  168.     return self
  169. )
  170.  
  171. --*=============================================================================*
  172. --*       Method name:    makeDigitalClock
  173. --*             Class:    Demo
  174. --*             Usage: makeDigitalClock self 
  175. --*-----------------------------------------------------------------------------*
  176. --*       Description: Creates and lays out the digital clock in the demo window.
  177. --*=============================================================================*
  178. method makeDigitalClock self {class Demo} ->
  179. (
  180.     --*=========================================================================*
  181.     --* Create a digital clock.
  182.     --*=========================================================================*
  183.     local dc := new DigitalClock boundary:(new rect x2:205 y2:50) \
  184.                                  format:@12hour
  185.     dc.position := new Point x:8 y:5
  186.     dc.fill := blackBrush
  187.     setDefaultAttr dc @brush (new Brush color:redColor)
  188.     setDefaultAttr dc @font (new PlatFormFont name:"Times")
  189.     setDefaultAttr dc @weight @bold
  190.     setDefaultAttr dc @size 36
  191.     setDefaultAttr dc @leading 36
  192.     setDefaultAttr dc @alignment @center    
  193.     
  194.     self.digitalClock := dc
  195.  
  196.     --*=========================================================================*
  197.     --* Add digital clock to the demo window.
  198.     --*=========================================================================*
  199.     prepend self dc
  200.     
  201.     return self
  202. )
  203.  
  204. --*=============================================================================*
  205. --*       Method name:    init
  206. --*             Class:    Demo
  207. --*             Usage: init self 
  208. --*-----------------------------------------------------------------------------*
  209. --*       Description: Creates a 220x110 window.
  210. --*=============================================================================*
  211. method init self {class Demo} #rest args ->
  212. (
  213.     apply nextMethod self boundary:(new Rect x2:220 y2:110) \
  214.         centered:true \
  215.         fill:(new Brush color:(new RGBColor red:200 green:200 blue:200)) \
  216.         name:"Digital Clock" args
  217.     return self
  218. )
  219.  
  220. --*=============================================================================*
  221. --*       Method name:    afterInit
  222. --*             Class:    Demo
  223. --*             Usage: afterInit self 
  224. --*-----------------------------------------------------------------------------*
  225. --*       Description: Calls methods to create the digital clock and buttons.
  226. --*=============================================================================*
  227. method afterInit self {class Demo} #rest args ->
  228. (                        
  229.     makeDigitalClock self
  230.     makeButtons self
  231.     
  232.     --*=========================================================================*
  233.     --* Display the demo window
  234.     --*=========================================================================*
  235.     show self
  236.     
  237.     return self
  238. )
  239.  
  240. --*=============================================================================*
  241. --*    Create a title container
  242. --*=============================================================================*
  243. object tc (TitleContainer)
  244.     dir        : theScriptDir
  245.     path    : "digtlclk.sxt" 
  246.     name    : "Digital Clock"
  247. end        
  248.     
  249. --*=============================================================================*
  250. --*    Create demo
  251. --*=============================================================================*
  252. object win (Demo)
  253.     title:tc
  254. end
  255.  
  256. --*=============================================================================*
  257. --*    Undefine global DirReps
  258. --*=============================================================================*
  259. mediaDir := undefined
  260.  
  261. --*=============================================================================*
  262. --*    Store module in the title container
  263. --*=============================================================================*
  264. append tc (getModule @DigitalClockModule)
  265. tc.startUpAction := (tc ->    load tc[1]
  266.                             startClock win[1]
  267.                             show win)
  268. close tc
  269. -->>>
  270.